package com.zzxx.userManagement.web;

import com.zzxx.userManagement.domain.UserInfo;
import com.zzxx.userManagement.service.UserInfoService;
import com.zzxx.userManagement.service.impl.UserInfoServiceImpl;
import com.zzxx.userManagement.utils.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/userInfo/QueryWithPageServlet")
public class QueryWithPageServlet extends HttpServlet {
    private UserInfoService userInfoService = new UserInfoServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.接收参数 currentPage  pageSize - null值的处理
        String currentPage = request.getParameter("currentPage");
        if (currentPage == null || currentPage.equals("")) {
            currentPage = "1";
        }
        String pageSize = request.getParameter("pageSize");
        if (pageSize == null || pageSize.equals("")) {
            pageSize = "4";
        }
        // 接收到条件查询的参数
        Map<String, String[]> condition =  request.getParameterMap();
        // 2.调用service 获得 PageBean 对象
        PageBean<UserInfo> pageBean = userInfoService.queryPage(currentPage, pageSize, condition);
        // 3.jsp显示
        request.setAttribute("pb", pageBean);
        request.setAttribute("con", condition);
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
